package com.joe.demo.netty;

import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultPromise;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;

/**
 * @Description
 * @Author gaojw
 * @Date 2024-08-29
 */
@Slf4j
public class TestNettyPromise {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        final NioEventLoopGroup group = new NioEventLoopGroup();
        // 可以主动创建 promise 结果容器
        DefaultPromise<Integer> promise = new DefaultPromise<>(group.next());

        new Thread(()->{
            log.info("开始计算...");
            promise.setSuccess(80);
        }).start();

        log.info("等待结果");
        log.info("结果是：{}", promise.get());
    }
}
